package com.hys.ultrasound.business.activity;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.blankj.utilcode.util.ToastUtils;
import com.hys.ultrasound.R;
import com.hys.ultrasound.base.ui.BaseActivity;
import com.hys.ultrasound.data.entity.Patient;
import com.lpjeremy.libmodule.gson.GsonUtil;

import butterknife.BindView;

/**
 * @desc:创建档案
 * @date:2020/10/14 13:58
 * @auther:lp
 * @version:1.1.6
 */
public class CreateArchiveActivity extends BaseActivity implements View.OnClickListener {
    @BindView(R.id.edtName)
    EditText mEdtName;
    @BindView(R.id.rdoMan)
    RadioButton mRdoMan;
    @BindView(R.id.rdoWomen)
    RadioButton mRdoWomen;
    @BindView(R.id.rdoSex)
    RadioGroup mRdoSex;
    @BindView(R.id.edtIdCard)
    EditText mEdtIdCard;
    @BindView(R.id.edtBodyHeight)
    EditText mEdtBodyHeight;
    @BindView(R.id.btnHistoryPatient)
    Button mBtnHistoryPatient;
    @BindView(R.id.edtAge)
    EditText mEdtAge;
    @BindView(R.id.edtPhone)
    EditText mEdtPhone;
    @BindView(R.id.edtBodyWeight)
    EditText mEdtBodyWeight;
    @BindView(R.id.btnNext)
    Button mBtnNext;

    private Patient mPatient;

    @Override
    protected void initView() {
        mBtnNext.setOnClickListener(this);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_create_archive;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btnNext://下一步、获取数据并跳转到扫描界面
                this.getPatient();
                //这里添加跳转到扫描界面的代码

                //下面三行代码是从扫码界面跳转到我们的界面，需要的参数名称和操作代码示例
                Intent intent = new Intent(mContext, MainActivity.class);
                intent.putExtra("QTParams", mPatient != null && !TextUtils.isEmpty(mPatient.getName()) ? GsonUtil.getInstance().objectToJson(mPatient) : "未填任何档案数据");
                startActivity(intent);
                break;
            default:
                ToastUtils.showShort("敬请期待！");
                break;
        }
    }

    private void getPatient() {
        mPatient = new Patient();
        mPatient.setName(mEdtName.getText().toString().trim());
        mPatient.setIdCard(mEdtIdCard.getText().toString().trim());
        mPatient.setBodyHeight(mEdtBodyHeight.getText().toString().trim());
        mPatient.setAge(mEdtAge.getText().toString().trim());
        mPatient.setPhone(mEdtPhone.getText().toString().trim());
        mPatient.setBodyWeight(mEdtBodyWeight.getText().toString().trim());
        mPatient.setSex(mRdoSex.getCheckedRadioButtonId() == mRdoMan.getId() ? "1" : (mRdoSex.getCheckedRadioButtonId() == mRdoWomen.getId() ? "2" : ""));
    }
}